package cn.codeforfun.service

import cn.codeforfun.dao.UserDao
import cn.codeforfun.entity.User
import org.junit.Before
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.annotation.Rollback
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.transaction.annotation.Transactional
import java.util.*
import javax.annotation.Resource
import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull

@SpringBootTest
@RunWith(SpringRunner::class)
@Rollback
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
open class UserServiceTest {
  @Resource
  private var userDao: UserDao? = null


  @Test
  fun testASave() {
    val user: User? = User()
    user?.username = "heiheihei"
    user?.password = "hahaha"
    userDao?.save(user)
    assertNotNull(user?.id)
    val findOne = userDao?.findOne(user?.id) as User
    assertNotNull(findOne)
  }

  @Test
  fun testBFindAll() {
    val user: User? = User()
    user?.username = "heiheihei"
    user?.password = "hahaha"
    userDao?.save(user)
    val findAll = userDao?.findAll()
    assertNotEquals(findAll?.size, 0)
  }
}